#include<bits/stdc++.h>
using namespace std;
struct line{
    int n;
    int num[200005]={0};
    int col[200005]={-1,0,1,0};
}a[11];
struct line c[11];
void a1(int n,int group){
    if(flag==1) return;
    for(int i=n-1;i>0;i--){
        if(a[group].col[i]!=a[group].col[n]){
              if(i==1){
                flag=1;
                c[group].num[i]=0;
              }
              continue;
        }else{
            c[group].num[i]=a[group].num[i];
            flag=1;
            break;
        }
    }
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>gup;
    for(int i=1;i<=gup;i++){
        cin>>a[i].n;
        for(int j=1;j<=a[i].n;j++){
            cin>>a[i].num[j];
        }
    }
    for(int i=1;i<=gup;i++){
        for(j=1;j<=a[i].n;j++){
                flag=0;
                a1(j,gup);
        }
    }

    for(int i=1;i<=gup;i++){
        for(int j=1;j<=a[i].n;j++){
            ans[i]+=c[i].num[j];
        }
    for(int i=1;i<=gup;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}
}

